home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Asm_course / assembler course / MENU_WINDOW.S < prev    next >
Encoding:
Text File  |  1992-04-27  |  3.7 KB  |  160 lines

  1.  
  2.  
  3.     ; Examine the SIMPLE_WINDOW.S before you try this one. In this source,
  4.     ; some more commands in the doslib are used. 
  5.  
  6.  
  7. START:    movem.l    d0-a6,-(a7)            ; save all registers on stack
  8.  
  9. OPENDOSLIB:
  10.     move.l    $4,a6
  11.     move.l    #doslibname,a1
  12.     jsr    -408(a6)
  13.     move.l    d0,dosbase
  14.     beq.w    error
  15.  
  16. OPEN:    move.l    #filename,d1            ; open a window (see filename)
  17.     move.l    #1006,d2
  18.     move.l    dosbase,a6
  19.     jsr    -30(a6)
  20.     move.l    d0,filehandle
  21.     beq.w    error
  22.  
  23. WRITE:    move.l    filehandle,d1            ; handle of file (window)
  24.     move.l    #menutext,d2            ; address of text
  25.     move.l    #endofmenutext-menutext,d3    ; length of text
  26.     move.l    dosbase,a6
  27.     jsr    -48(a6)                ; 'Write'
  28.  
  29. READ:    ; read some text from this window (you must type something!)
  30.     ; the READ command in the doslib is used. It needs 3 parameters:
  31.  
  32.     move.l    filehandle,d1            ; again, d1 must contain the
  33.                         ; handle of our file (window)
  34.     move.l    #buffer,d2            ; d2 must contain the address
  35.                         ; of the buffer, where the
  36.                         ; text to be read will be 
  37.                         ; stored to.
  38.     move.l    #5,d3                ; d3=the amount of bytes to be
  39.                         ; read. (unless you type
  40.                         ; return earlier)
  41.     move.l    dosbase,a6
  42.     jsr    -42(a6)                ; call the 'read' command
  43.  
  44.  
  45. CHECK:    move.b    buffer,d0            ; check first character in the
  46.                         ; buffer:
  47.     cmp.b    #"1",d0
  48.     beq.s    routine1            ; switch to each routine
  49.  
  50.     cmp.b    #"2",d0                ; for the different possible
  51.     beq.s    routine2            ; menu-options
  52.  
  53.     cmp.b    #"3",d0
  54.     beq.s    routine3
  55.  
  56.     cmp.b    #"4",d0
  57.     beq.w    close                ; 4: end-of-program
  58.  
  59.     ; none of the possible characters were entered, so the user typed
  60.     ; something else: display an error message, using the WRITE command:
  61.  
  62.     move.l    filehandle,d1            ; handle of output-file
  63.     move.l    #errormessage,d2        ; address of the text
  64.     move.l    #endoferror-errormessage,d3    ; length of text
  65.     move.l    dosbase,a6
  66.     jsr    -48(a6)                ; 'Write'
  67.  
  68. DELAY:    ; now wait 1 second and re-display the menu
  69.  
  70.     move.l    #50,d1                ; time to delay (1 sec)
  71.     move.l    dosbase,a6
  72.     jsr    -198(a6)            ; 'delay'
  73.     
  74.     bra    WRITE                ; and goto 'WRITE'
  75.  
  76. *********
  77.  
  78. routine1:
  79.     move.l    filehandle,d1            ; handle of output-file
  80.     move.l    #message1,d2            ; address of the text
  81.     move.l    #endm1-message1,d3        ; length of text
  82.     move.l    dosbase,a6
  83.     jsr    -48(a6)                ; 'Write'
  84.     bra    delay                ; continue at 'delay'
  85.  
  86. routine2:
  87.     move.l    filehandle,d1            ; handle of output-file
  88.     move.l    #message2,d2            ; address of the text
  89.     move.l    #endm2-message2,d3        ; length of text
  90.     move.l    dosbase,a6
  91.     jsr    -48(a6)                ; 'Write'
  92.     bra    delay                ; continue at 'delay'
  93.     
  94. routine3:
  95.     move.l    filehandle,d1            ; handle of output-file
  96.     move.l    #message3,d2            ; address of the text
  97.     move.l    #endm3-message3,d3        ; length of text
  98.     move.l    dosbase,a6
  99.     jsr    -48(a6)                ; 'Write'
  100.     bra    delay                ; continue at 'delay'
  101.  
  102. ***********
  103.  
  104. CLOSE:    ; now close the file, opened with the OPEN command. This will in this
  105.     ; case close the window.
  106.  
  107.     move.l    filehandle,d1            ; d1 must contain the file-
  108.                         ; handle.
  109.     move.l    dosbase,a6
  110.     jsr    -36(a6)                ; call the 'close' command.
  111.  
  112.  
  113. error:    movem.l    (a7)+,d0-a6            ; restore all registers
  114.     rts                    ; end of program
  115.  
  116. ***************************
  117.  
  118. ;; Here starts the DATA part. Make sure it is situated BEHIND the code-part
  119.  
  120.  
  121. doslibname:    dc.b    "dos.library",0
  122. filename:    dc.b    "con:100/50/440/180/ Simple Menu, made for Mike ",0
  123.  
  124.  
  125. menutext:    dc.b    27,"c"        ; 27,"c" clears the window
  126.         dc.b    10        ; 10 means 'return'
  127.         dc.b    10
  128.         dc.b    "  Please make a selection:",10
  129.         dc.b    "  ------------------------",10
  130.         dc.b    10
  131.         dc.b    10
  132.         dc.b    "  1. blabla",10
  133.         dc.b    "  2. blabla",10
  134.         dc.b    "  3. blabla",10
  135.         dc.b    "  4. exit",10
  136.         dc.b    10
  137.         dc.b    "  Your choice: ",0
  138. endofmenutext:
  139.  
  140. message1:    dc.b    10,"You typed '1'",0
  141. endm1:
  142.  
  143. message2:    dc.b    10,"You typed '2'",0
  144. endm2:
  145.  
  146. message3:    dc.b    10,"You typed '3'",0
  147. endm3:
  148.  
  149. errormessage:    dc.b    10,"Wrong selection ! Please try again !",0
  150. endoferror:
  151.  
  152. buffer:        blk.b    5,0    ; reserve 5 bytes to read some text
  153.  
  154.         even
  155.  
  156.  
  157. dosbase:    dc.l    0
  158. filehandle:    dc.l    0
  159.  
  160.